package org.firebug.spring.boot.jpa.service;

import org.firebug.spring.boot.jpa.repository.dao.UserDao;
import org.firebug.spring.boot.jpa.repository.entity.UserEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.math.BigDecimal;

@Service
public class UserService {
    @Resource
    private UserDao userDao;

    @Transactional(readOnly = false, rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    public void updateById() throws Exception {
        UserEntity user1 = userDao.findOne(1);
        user1.setSalary(BigDecimal.TEN);
        for(UserEntity user2 : userDao.findAll()) {
            System.out.println(user2.getSalary());
        }
    }
}
